package com.binguo.model.mapper;

import com.binguo.model.model.SideBoard;
import com.binguo.model.model.SideBoardExample;
import java.util.List;

import com.binguo.model.wxapi.vo.AiyouweiGetCellVO;
import com.binguo.model.wxapi.vo.ShopSideBoardVO;
import com.binguo.model.wxapi.vo.SideBoardVO;

import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;


public interface SideBoardMapper {
    int countByExample(SideBoardExample example);

    int deleteByExample(SideBoardExample example);

    int deleteByPrimaryKey(Integer id);

    int insert(SideBoard record);

    int insertSelective(SideBoard record);

    List<SideBoard> selectByExample(SideBoardExample example);

    SideBoard selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") SideBoard record, @Param("example") SideBoardExample example);

    int updateByExample(@Param("record") SideBoard record, @Param("example") SideBoardExample example);

    int updateByPrimaryKeySelective(SideBoard record);

    int updateByPrimaryKey(SideBoard record);

    AiyouweiGetCellVO selectAllNotUseCell(@Param("branchId")Integer branchId,@Param("shopId") Integer shopId);

    AiyouweiGetCellVO selectCell(@Param("branchId")Integer branchId,@Param("shopId") Integer shopId,@Param("cell")Integer cell);

    SideBoardVO selectByShopIdAndBranchId(@Param("branchId")Integer branchId, @Param("shopId") Integer shopId,@Param("cashierDeskId")Integer cashierDeskId);

    SideBoard selectByMealCode(@Param("mealCode")String mealCode);

    @Select("select id as id,branch_id as branchId,status as status ,shop_id as shopId,cashier_desk_id as cashierDeskId,branch_side_board_id as branchSideBoardId,jpush_register_id as jpushRegisterId ,parent_id as parentId,side_board_name as sideBoardName from side_board where cashier_desk_id = #{cashierDeskId} and parent_id = 0")
    SideBoard selectByCashierId(@Param("cashierDeskId") Integer cashierDeskId);

    @Select("select id as id,branch_id as branchId,status as status ,shop_id as shopId,cashier_desk_id as cashierDeskId,branch_side_board_id as branchSideBoardId from side_board where shop_id = #{shopId}")
    List<ShopSideBoardVO> selectByShopId(@Param("shopId")Integer shopId);

    @Select("select count(*) from side_board_cells where side_board_cells.side_board_id in (select id from side_board where side_board.cashier_desk_id = #{cashierDeskId} and side_board.`status` = 1)")
    Integer selectCellsCount(@Param("cashierDeskId") Integer cashierDeskId);

    @Select("select side_board.branch_side_board_id from side_board where side_board.branch_id = #{branchId} and side_board.shop_id = #{shopId} and side_board.branch_side_board_id != 0 ORDER BY side_board.branch_side_board_id desc limit 1")
    Integer selectMaxSideBranchId(@Param("branchId")Integer branchId,@Param("shopId")Integer shopId);

    @Select("select count(side_board_cells.id) as cellNum, side_board.id as id,side_board.branch_id as branchId,side_board.status as status ,side_board.shop_id as shopId,side_board.cashier_desk_id as cashierDeskId,side_board.branch_side_board_id as branchSideBoardId,side_board.jpush_register_id as jpushRegisterId ,side_board.parent_id as parentId,side_board_name as sideBoardName from side_board INNER JOIN side_board_cells on side_board.id = side_board_cells.side_board_id where side_board.cashier_desk_id = #{cashierDeskId} GROUP BY side_board_cells.side_board_id")
    List<SideBoard> selectListByCashierId(@Param("cashierDeskId") Integer cashierDeskId);

    @Update("update side_board_cells set status = 1 where side_board_id = #{sideBoardId}")
    Integer updateBySideBoardId(@Param("sideBoardId") Integer sideBoardId);

    @Select("select id as id,branch_id as branchId,status as status ,shop_id as shopId,cashier_desk_id as cashierDeskId ,parent_id as parentId,branch_side_board_id as branchSideBoardId ,side_board_name as sideBoardName from side_board where branch_id = #{branchId} and shop_id = #{shopId} and status = 1")
    List<SideBoard> selectBranchSideBoard(@Param("branchId")Integer branchId,@Param("shopId")Integer shopId);

    @Select("select * from side_board where shop_id = #{shopId} and status = 1")
    List<SideBoard> selectShopSideBoard(@Param("shopId")Integer shopId);

    @Select("select id as id,branch_id as branchId,status as status ,shop_id as shopId,cashier_desk_id as cashierDeskId,branch_side_board_id as branchSideBoardId,jpush_register_id as jpushRegisterId ,parent_id as parentId from side_board where id = #{id}")
    SideBoard selectSideBoardById(@Param("id") Integer id);

    AiyouweiGetCellVO selectShopSideBoardInfo(@Param("branchId")Integer branchId,@Param("shopId") Integer shopId,@Param("cashierDeskId")Integer cashierDeskId,@Param("cell")String cell);


    SideBoard selectSideBoardId(@Param("id") Integer cashierDeskId,@Param("branchId") Integer branchId,@Param("shopId") Integer shopId);

    String selectCellForQrCodeOrder(@Param("cashierDeskId")Integer cashierDeskId,@Param("list")List<String> cellNo);

    @Select("select count(*) from side_board where side_board.parent_id = #{id} and side_board.status = 1;")
    Integer selectCount(@Param("id") Integer id);

    @Select("SELECT id,side_board_name as sideBoardName FROM side_board where side_board.branch_id = #{branchId} and parent_id = 0 and side_board.board_type = 2 and status = 1 and cashier_desk_id != #{cashierDeskId} ")
    List<SideBoard> selectAllCustomerBoard(@Param("branchId")Integer branchId,@Param("cashierDeskId")Integer cashierDeskId);

    @Select("select id as id,branch_id as branchId,status as status ,shop_id as shopId,cashier_desk_id as cashierDeskId,branch_side_board_id as branchSideBoardId,jpush_register_id as jpushRegisterId ,parent_id as parentId from side_board where id = (select bind_board from side_board where board_type = 2 and cashier_desk_id = 2110) and parent_id = 0")
    SideBoard selectBindBoardByCashierIdAndBoardType(@Param("cashierDeskId") Integer cashierDeskId);

}